<!-- 搜索表单 -->
<template>
  <ele-card :body-style="{ paddingBottom: '2px' }">
    <el-form label-width="72px" @keyup.enter="search" inline>
      <!-- <el-form-item label="所属站点">
        <el-radio-group v-model="form.site_id" @change="search">
          <el-radio-button :label="0">全部</el-radio-button>
          <el-radio-button
            v-for="item in cityList"
            :key="item.id"
            :label="item.id"
            :value="item.id"
          >
            {{ item.region_name }}
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br /> -->
      <el-form-item label="状态">
        <el-radio-group v-model="form.status" @change="search">
          <el-radio-button :label="1">正常</el-radio-button>
          <el-radio-button :label="0">离职</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="所属部门">
        <el-radio-group v-model="form.roles" @change="search">
          <el-radio-button :label="0">全部</el-radio-button>
          <el-radio-button
            v-for="item in roleList"
            :key="item.id"
            :label="item.id"
            :value="item.id"
          >
            {{ item.title }}
          </el-radio-button>
        </el-radio-group>
      </el-form-item>
      <br />
      <el-form-item label="登录账号">
        <el-input clearable v-model.trim="form.username" placeholder="请输入" />
      </el-form-item>

      <el-form-item label="姓名">
        <el-input clearable v-model.trim="form.realname" placeholder="请输入" />
      </el-form-item>

      <el-form-item label-width="16px">
        <el-button type="primary" @click="search">查询</el-button>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
  </ele-card>
</template>

<script setup>
  import { ref } from 'vue';
  import { EleMessage } from 'ele-admin-plus/es';
  import { useFormData } from '@/utils/use-form-data';
  import { listRoles } from '@/api/system/role';
  import { getCityList } from '@/api/system/region';
  const emit = defineEmits(['search']);

  /** 表单数据 */
  const [form, resetFields] = useFormData({
    username: '',
    realname: '',
    site_id: 0,
    status: 1,
    roles: 0
  });

  /** 角色数据 */
  const roleList = ref([]);

  /** 站点数据 */
  const cityList = ref([]);

  /** 搜索 */
  const search = () => {
    emit('search', { ...form });
  };

  /**  重置 */
  const reset = () => {
    resetFields();
    search();
  };

  /** 获取角色数据 */
  listRoles({})
    .then((res) => {
      roleList.value = res.list;
    })
    .catch((e) => {
      EleMessage.error(e.message);
    });

  /** 获取站点数据 */
  // getCityList({})
  //   .then((res) => {
  //     cityList.value = res.list;
  //   })
  //   .catch((e) => {
  //     EleMessage.error(e.message);
  //   });
</script>
